export default {
  name: "contract-approval-manage",
  data() {
    return {
      isActive: 0,
      isShow: true,
      tableTopBtn: [
        { label: "全部", value: "approvalAll" },
        { label: "待审批", value: "approvalPending" },
        { label: "已审批", value: "approvalPass" },
      ],
      // 非锁定表格
      unfixedTableThead: [
        {
          label: "审批类型",
          prop: "todoData.businessBillTypeName",
          width: "100",
        },
        {
          label: "盘点单名称",
          prop: "businessData.inventoryName",
          width: "150",
        },
        {
          label: "填报单位",
          prop: "businessData.reportInOrgName",
          width: "180",
        },
        {
          label: "仓库名称",
          prop: "businessData.warehouseName",
          width: "150",
        },
        {
          label: "盘点数量",
          prop: "businessData.inventoryCountString",
          width: "120",
        },
        {
          label: "含税金额（元）",
          prop: "businessData.inventoryMoneyString",
          width: "120",
          align: "right",
        },
        {
          label: "编制人",
          prop: "businessData.reportUsername",
          width: "80",
        },
        {
          label: "编制日期",
          prop: "businessData.reportTime",
          width: "130",
        },
        {
          label: "审批状态",
          prop: "todoData.workItemStatusString",
          width: "100",
        },
      ],
      // 审批类型
      // storageTypeList: [
      //   { label: "待审批", value: "1" },
      //   { label: "已审批", value: "2" }
      // ],
      // 审批状态
      workItemStatusList: [
        { label: "待审批", value: "0" },
        { label: "已审批", value: "1" },
      ],
      // 审批类型
      approvalTypeList: [
        { label: "财务出库", value: "S0407" },
        { label: "财务出库冲销", value: "S0408" },
      ],
    };
  },
  methods: {
    // 默认渲染表格
    renderTable() {
      const localTableData = localStorage.getItem(this.tableName)
        ? JSON.parse(localStorage.getItem(this.tableName))
        : [];
      let unfixedTableThead = this.unfixedTableThead.concat(
        this.fixedTableThead
      );
      let localTableDataStr = localTableData.map(
        ({ label, prop, formatter, align }) =>
          JSON.stringify({ label, prop, formatter, align })
      );
      let unfixedTableTheadStr = unfixedTableThead.map(
        ({ label, prop, width, formatter, align }) =>
          JSON.stringify({ label, prop, formatter, align })
      );

      if (localTableData.length === unfixedTableThead.length) {
        let flag = localTableDataStr.every((item) =>
          unfixedTableTheadStr.includes(item)
        );
        if (flag) {
          // 完全相同
          this.tableTheadOptions = localTableData;
          this.tableThead = localTableData;
          this.unfixedTableThead = localTableData.filter((item) => {
            return !this.fixedTableThead.find(
              (cItem) => item.prop === cItem.prop
            );
          });
        } else {
          // 长度相同但值不同
          this.tableThead = this.unfixedTableThead.concat(this.fixedTableThead);
          const comment = JSON.stringify(this.tableThead);
          localStorage.setItem(this.tableName, comment);
          const localTableData = JSON.parse(
            localStorage.getItem(this.tableName)
          );
          this.tableTheadOptions = localTableData;
        }
      } else {
        // 长度不同
        this.tableThead = this.unfixedTableThead.concat(this.fixedTableThead);
        const comment = JSON.stringify(this.tableThead);
        localStorage.setItem(this.tableName, comment);
        const localTableData = JSON.parse(localStorage.getItem(this.tableName));
        this.tableTheadOptions = localTableData;
      }
    },

    // 页签跳转
    tableTopChange({ value }) {
      this.isFocus = value;
      this.$router.push(`/inventoryManagement/inventoryApprove/${value}`);
    },

    // 跳转详情页
    handleGoDetail(row, index, from) {
      const { todoData, businessData } = row;
      const { businessBillTypeCode } = todoData;
      const { id } = businessData;
      const jumpInformation = {
        S0410: { states: "inventoryDetail" },
      };

      this.$router.push({
        path: `/inventoryManagement/inventoryApprove/approvalDetail`,
        query: {
          id,
          ...jumpInformation[businessBillTypeCode],
          // name: billName,
          from,
        },
      });
    },

    // 跳转审核页
    handleGoApproval(row) {
      const { todoData, businessData } = row;
      const { businessBillTypeCode } = todoData;
      const { id } = businessData;

      this.$store.dispatch("setBusinessList", todoData);
      const businessList = JSON.stringify(todoData);
      sessionStorage.setItem("businessList", businessList);

      const jumpInformation = {
        S0410: { states: "inventoryApproval" },
      };

      this.$router.push({
        path: `/inventoryManagement/inventoryApprove/approvalDetail/`,
        query: {
          id,
          ...jumpInformation[businessBillTypeCode],
          from: "pending",
        },
      });
    },
  },
};
